package com.hzhr.iot.user.convertor;

import com.hzhr.iot.user.convertor.custom.*;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.core.util.HzhrJsonUtil;
import java.util.Map;
import com.hzhr.iot.user.model.action.ActionModel;
import com.hzhr.iot.user.model.action.ActionPostModel;
import com.hzhr.iot.user.model.action.ActionPutModel;
import com.hzhr.iot.user.entity.ActionEntity;
import com.hzhr.iot.user.entity.ext.ActionEntityExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.hzhr.iot.user.model.action.ActionModel;
import com.hzhr.iot.user.model.action.ActionGetModel;
import com.hzhr.iot.user.model.action.ActionPostModel;
import com.hzhr.iot.user.model.action.ActionPutModel;
import com.hzhr.iot.user.queryModel.custom.ActionCustomQueryModel;

@Component
public class ActionConvertor {
    @Autowired
    ActionInRoleCustomConvertor actionInRoleCustomConvertor;
    @Autowired
    CompanyCustomConvertor companyCustomConvertor;
    @Autowired
    DeptCustomConvertor deptCustomConvertor;
    @Autowired
    OptionsCustomConvertor optionsCustomConvertor;
    @Autowired
    ResourceCustomConvertor resourceCustomConvertor;
    @Autowired
    ResourceInActionCustomConvertor resourceInActionCustomConvertor;
    @Autowired
    RoleCustomConvertor roleCustomConvertor;
    @Autowired
    UserCustomConvertor userCustomConvertor;
    @Autowired
    UserInRoleCustomConvertor userInRoleCustomConvertor;

    public ActionEntity actionModel2entity(ActionModel in) {
        //未转换字段: createUserId createTime updateUserId isValid updateTime state 
        if (in == null) return null;
        ActionEntity result = new ActionEntity();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setCode(HzhrTypeUtil.string2string(in.getCode()));
        result.setUrl(HzhrTypeUtil.string2string(in.getUrl()));
        result.setType(HzhrTypeUtil.string2string(in.getType()));
        result.setLevel(HzhrTypeUtil.integer2integer(in.getLevel()));
        result.setParentId(HzhrTypeUtil.integer2integer(in.getParentId()));
        result.setSort(HzhrTypeUtil.integer2integer(in.getSort()));
        result.setAppCode(HzhrTypeUtil.integer2integer(in.getAppCode()));
        return result;
    }
    public ActionEntity actionModel2entity(ActionModel in, ActionEntity ori) {
        //未转换字段: createUserId createTime updateUserId isValid updateTime state 
        if (in == null) return null;
        ActionEntity result = ori;

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setCode(HzhrTypeUtil.string2string(in.getCode()));
        result.setUrl(HzhrTypeUtil.string2string(in.getUrl()));
        result.setType(HzhrTypeUtil.string2string(in.getType()));
        result.setLevel(HzhrTypeUtil.integer2integer(in.getLevel()));
        result.setParentId(HzhrTypeUtil.integer2integer(in.getParentId()));
        result.setSort(HzhrTypeUtil.integer2integer(in.getSort()));
        result.setAppCode(HzhrTypeUtil.integer2integer(in.getAppCode()));
        return result;
    }
    public List<ActionEntity> actionModelList2entityList(List<ActionModel> in) {
        if (in == null) return null;
        List<ActionEntity> result = new ArrayList<>();
        for (ActionModel item : in) {
            result.add(actionModel2entity(item));
        }
        return result;
    }
    public ActionModel entity2actionModel(ActionEntity in) {
        //未转换字段: userId 
        if (in == null) return null;
        ActionModel result = new ActionModel();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setCode(HzhrTypeUtil.string2string(in.getCode()));
        result.setUrl(HzhrTypeUtil.string2string(in.getUrl()));
        result.setType(HzhrTypeUtil.string2string(in.getType()));
        result.setLevel(HzhrTypeUtil.integer2integer(in.getLevel()));
        result.setParentId(HzhrTypeUtil.integer2integer(in.getParentId()));
        result.setSort(HzhrTypeUtil.integer2integer(in.getSort()));
        result.setAppCode(HzhrTypeUtil.integer2integer(in.getAppCode()));
        return result;
    }
    public List<ActionModel> entityList2actionModelList(List<ActionEntity> in) {
        if (in == null) return null;
        List<ActionModel> result = new ArrayList<>();
        for (ActionEntity item : in) {
            result.add(entity2actionModel(item));
        }
        return result;
    }
    public ActionModel ext2actionModel(ActionEntityExt in) {
        //未转换字段: userId 
        if (in == null) return null;
        ActionModel result = new ActionModel();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setCode(HzhrTypeUtil.string2string(in.getCode()));
        result.setUrl(HzhrTypeUtil.string2string(in.getUrl()));
        result.setType(HzhrTypeUtil.string2string(in.getType()));
        result.setLevel(HzhrTypeUtil.integer2integer(in.getLevel()));
        result.setParentId(HzhrTypeUtil.integer2integer(in.getParentId()));
        result.setSort(HzhrTypeUtil.integer2integer(in.getSort()));
        result.setAppCode(HzhrTypeUtil.integer2integer(in.getAppCode()));
        return result;
    }
    public List<ActionModel> extList2actionModelList(List<ActionEntityExt> in) {
        if (in == null) return null;
        List<ActionModel> result = new ArrayList<>();
        for (ActionEntityExt item : in) {
            result.add(ext2actionModel(item));
        }
        return result;
    }
    public ActionGetModel extList2actionGetModel(List<ActionEntityExt> extList, Integer total, Integer changeCount, Map<String, Object> query) {
        List<ActionModel> modelList = extList2actionModelList(extList);
        if (modelList == null) {
            ActionGetModel result = new ActionGetModel();
            result.setTotal(total);
            result.setChangeCount(changeCount);
            return result;
        }

         String _show = HzhrTypeUtil.object2string(query.get("_show"));
         Boolean _show_info = query.get("_show_info") != null ? Boolean.parseBoolean(query.get("_show_info").toString()) : false;

        if (!_show_info) {
            for (ActionModel model : modelList) {
                model.setName(null);
                model.setCode(null);
                model.setUrl(null);
                model.setType(null);
                model.setLevel(null);
                model.setParentId(null);
                model.setSort(null);
                model.setAppCode(null);
                model.setUserId(null);
            }
        }

        ActionGetModel result = new ActionGetModel();
        if ("one".equals(_show)) {
            if (modelList.size() > 0) {
                result.setModel(modelList.get(0));
            }
         }
        if ("list".equals(_show)) {
            result.setModelList(modelList);
        }
        result.setTotal(total);
        result.setChangeCount(changeCount);
        return result;
    }
    public ActionGetModel entity2actionGetModel(ActionEntity entity, Integer total, Integer changeCount, Map<String, Object> query) {
        List<ActionEntityExt> extList = new ArrayList<>();
        if (entity == null) return extList2actionGetModel(extList, total, changeCount, query);
        extList.add(HzhrJsonUtil.convertObjectType(entity, ActionEntityExt.class));
        return extList2actionGetModel(extList, total, changeCount, query);
     }
    public ActionEntity actionPostModel2entity(ActionPostModel in) {
        //未转换字段: createUserId createTime updateUserId isValid updateTime id state 
        if (in == null) return null;
        ActionEntity result = new ActionEntity();

        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setCode(HzhrTypeUtil.string2string(in.getCode()));
        result.setUrl(HzhrTypeUtil.string2string(in.getUrl()));
        result.setType(HzhrTypeUtil.string2string(in.getType()));
        result.setLevel(HzhrTypeUtil.integer2integer(in.getLevel()));
        result.setParentId(HzhrTypeUtil.integer2integer(in.getParentId()));
        result.setSort(HzhrTypeUtil.integer2integer(in.getSort()));
        result.setAppCode(HzhrTypeUtil.integer2integer(in.getAppCode()));
        return result;
    }
    public ActionEntity actionPostModel2entity(ActionPostModel in, ActionEntity ori) {
        //未转换字段: createUserId createTime updateUserId isValid updateTime id state 
        if (in == null) return null;
        ActionEntity result = ori;

        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setCode(HzhrTypeUtil.string2string(in.getCode()));
        result.setUrl(HzhrTypeUtil.string2string(in.getUrl()));
        result.setType(HzhrTypeUtil.string2string(in.getType()));
        result.setLevel(HzhrTypeUtil.integer2integer(in.getLevel()));
        result.setParentId(HzhrTypeUtil.integer2integer(in.getParentId()));
        result.setSort(HzhrTypeUtil.integer2integer(in.getSort()));
        result.setAppCode(HzhrTypeUtil.integer2integer(in.getAppCode()));
        return result;
    }
    public List<ActionEntity> actionPostModelList2entityList(List<ActionPostModel> in) {
        if (in == null) return null;
        List<ActionEntity> result = new ArrayList<>();
        for (ActionPostModel item : in) {
            result.add(actionPostModel2entity(item));
        }
        return result;
    }
    public ActionPostModel entity2actionPostModel(ActionEntity in) {
        //未转换字段: 
        if (in == null) return null;
        ActionPostModel result = new ActionPostModel();

        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setCode(HzhrTypeUtil.string2string(in.getCode()));
        result.setUrl(HzhrTypeUtil.string2string(in.getUrl()));
        result.setType(HzhrTypeUtil.string2string(in.getType()));
        result.setLevel(HzhrTypeUtil.integer2integer(in.getLevel()));
        result.setParentId(HzhrTypeUtil.integer2integer(in.getParentId()));
        result.setSort(HzhrTypeUtil.integer2integer(in.getSort()));
        result.setAppCode(HzhrTypeUtil.integer2integer(in.getAppCode()));
        return result;
    }
    public List<ActionPostModel> entityList2actionPostModelList(List<ActionEntity> in) {
        if (in == null) return null;
        List<ActionPostModel> result = new ArrayList<>();
        for (ActionEntity item : in) {
            result.add(entity2actionPostModel(item));
        }
        return result;
    }
    public ActionPostModel ext2actionPostModel(ActionEntityExt in) {
        //未转换字段: 
        if (in == null) return null;
        ActionPostModel result = new ActionPostModel();

        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setCode(HzhrTypeUtil.string2string(in.getCode()));
        result.setUrl(HzhrTypeUtil.string2string(in.getUrl()));
        result.setType(HzhrTypeUtil.string2string(in.getType()));
        result.setLevel(HzhrTypeUtil.integer2integer(in.getLevel()));
        result.setParentId(HzhrTypeUtil.integer2integer(in.getParentId()));
        result.setSort(HzhrTypeUtil.integer2integer(in.getSort()));
        result.setAppCode(HzhrTypeUtil.integer2integer(in.getAppCode()));
        return result;
    }
    public List<ActionPostModel> extList2actionPostModelList(List<ActionEntityExt> in) {
        if (in == null) return null;
        List<ActionPostModel> result = new ArrayList<>();
        for (ActionEntityExt item : in) {
            result.add(ext2actionPostModel(item));
        }
        return result;
    }
    public ActionEntity actionPutModel2entity(ActionPutModel in) {
        //未转换字段: createUserId createTime updateUserId isValid updateTime id state 
        if (in == null) return null;
        ActionEntity result = new ActionEntity();

        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setCode(HzhrTypeUtil.string2string(in.getCode()));
        result.setUrl(HzhrTypeUtil.string2string(in.getUrl()));
        result.setType(HzhrTypeUtil.string2string(in.getType()));
        result.setLevel(HzhrTypeUtil.integer2integer(in.getLevel()));
        result.setParentId(HzhrTypeUtil.integer2integer(in.getParentId()));
        result.setSort(HzhrTypeUtil.integer2integer(in.getSort()));
        result.setAppCode(HzhrTypeUtil.integer2integer(in.getAppCode()));
        return result;
    }
    public ActionEntity actionPutModel2entity(ActionPutModel in, ActionEntity ori) {
        //未转换字段: createUserId createTime updateUserId isValid updateTime id state 
        if (in == null) return null;
        ActionEntity result = ori;

        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setCode(HzhrTypeUtil.string2string(in.getCode()));
        result.setUrl(HzhrTypeUtil.string2string(in.getUrl()));
        result.setType(HzhrTypeUtil.string2string(in.getType()));
        result.setLevel(HzhrTypeUtil.integer2integer(in.getLevel()));
        result.setParentId(HzhrTypeUtil.integer2integer(in.getParentId()));
        result.setSort(HzhrTypeUtil.integer2integer(in.getSort()));
        result.setAppCode(HzhrTypeUtil.integer2integer(in.getAppCode()));
        return result;
    }
    public List<ActionEntity> actionPutModelList2entityList(List<ActionPutModel> in) {
        if (in == null) return null;
        List<ActionEntity> result = new ArrayList<>();
        for (ActionPutModel item : in) {
            result.add(actionPutModel2entity(item));
        }
        return result;
    }
    public ActionPutModel entity2actionPutModel(ActionEntity in) {
        //未转换字段: 
        if (in == null) return null;
        ActionPutModel result = new ActionPutModel();

        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setCode(HzhrTypeUtil.string2string(in.getCode()));
        result.setUrl(HzhrTypeUtil.string2string(in.getUrl()));
        result.setType(HzhrTypeUtil.string2string(in.getType()));
        result.setLevel(HzhrTypeUtil.integer2integer(in.getLevel()));
        result.setParentId(HzhrTypeUtil.integer2integer(in.getParentId()));
        result.setSort(HzhrTypeUtil.integer2integer(in.getSort()));
        result.setAppCode(HzhrTypeUtil.integer2integer(in.getAppCode()));
        return result;
    }
    public List<ActionPutModel> entityList2actionPutModelList(List<ActionEntity> in) {
        if (in == null) return null;
        List<ActionPutModel> result = new ArrayList<>();
        for (ActionEntity item : in) {
            result.add(entity2actionPutModel(item));
        }
        return result;
    }
    public ActionPutModel ext2actionPutModel(ActionEntityExt in) {
        //未转换字段: 
        if (in == null) return null;
        ActionPutModel result = new ActionPutModel();

        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setCode(HzhrTypeUtil.string2string(in.getCode()));
        result.setUrl(HzhrTypeUtil.string2string(in.getUrl()));
        result.setType(HzhrTypeUtil.string2string(in.getType()));
        result.setLevel(HzhrTypeUtil.integer2integer(in.getLevel()));
        result.setParentId(HzhrTypeUtil.integer2integer(in.getParentId()));
        result.setSort(HzhrTypeUtil.integer2integer(in.getSort()));
        result.setAppCode(HzhrTypeUtil.integer2integer(in.getAppCode()));
        return result;
    }
    public List<ActionPutModel> extList2actionPutModelList(List<ActionEntityExt> in) {
        if (in == null) return null;
        List<ActionPutModel> result = new ArrayList<>();
        for (ActionEntityExt item : in) {
            result.add(ext2actionPutModel(item));
        }
        return result;
    }
    public ActionCustomQueryModel actionService_query2queryModel(Map<String, Object> query) {
        ActionCustomQueryModel queryModel = new ActionCustomQueryModel();

        Integer _equal_id = HzhrTypeUtil.object2integer(query.get("_equal_id"));
        if (_equal_id != null) {
            queryModel.setEqual_id(_equal_id);
         }

        String _equal_appCode = HzhrTypeUtil.object2string(query.get("_equal_appCode"));
        if (_equal_appCode != null) {
            queryModel.setEqual_appCode(_equal_appCode);
         }

        Integer _equal_userId = HzhrTypeUtil.object2integer(query.get("_equal_userId"));
        if (_equal_userId != null) {
            queryModel.setEqual_actionInRoleExtList_roleExt_userInRoleExtList_userId(_equal_userId);
         }

        Boolean _show_info = HzhrTypeUtil.object2boolean(query.get("_show_info"));
        if (_show_info != null && _show_info) {
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
        }

        Integer page = HzhrTypeUtil.object2integer(query.get("_page"));
        Integer count = HzhrTypeUtil.object2integer(query.get("_count"));
        queryModel.setPage(page, count);

        return queryModel;
    }

}

